﻿using System.Collections.Generic;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Data;
using System.Linq;

namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        /// <summary>
        /// GetJob is used to collect the tasks to finish the order creation
        /// </summary>
        /// <param name="FInterID"></param>
        /// <returns></returns>
        public void SJDWB13(DataSet db)
        {
            try
            {


                DataTable tbWBBST = db.Tables["ICC_STOCK"];
                DataTable dtOutput = new DataTable();
                int idx = 1;
                int x = 3;
                #region======Title===========
                exAgent.SetCellValue(x, idx++, "时间区间"); dtOutput.Columns.Add("TIMERANGE", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "车间"); dtOutput.Columns.Add("AMLB", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "品种"); dtOutput.Columns.Add("WAART", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "品名"); dtOutput.Columns.Add("WABEZ", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷号"); dtOutput.Columns.Add("WBEWSTKNR", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "挡车工"); dtOutput.Columns.Add("DCG", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "产量"); dtOutput.Columns.Add("DCGQTY", typeof(System.Decimal));
                exAgent.SetCellValue(x, idx++, "等级"); dtOutput.Columns.Add("WBEWZENSURKZ", typeof(System.String));  
                exAgent.SetCellValue(x, idx++, "织造班"); dtOutput.Columns.Add("WBFMARKART", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "验布班"); dtOutput.Columns.Add("WBBREFSCHL", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷数"); dtOutput.Columns.Add("PCS", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "米数"); dtOutput.Columns.Add("WBBSSTKLG", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "卷次"); dtOutput.Columns.Add("WBBZMT", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "批号"); dtOutput.Columns.Add("ABPARTEX", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "门幅"); dtOutput.Columns.Add("WBBSBRT", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "纬密"); dtOutput.Columns.Add("WBBHHK1", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "工号"); dtOutput.Columns.Add("WBBNEUBEN", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "机台号"); dtOutput.Columns.Add("WBBWMLFDNR", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "生产日期"); dtOutput.Columns.Add("WBEWBUCHDAT", typeof(System.String));
                exAgent.SetCellValue(x, idx++, "疵点"); dtOutput.Columns.Add("REMARK", typeof(System.String));
                #endregion
                dtOutput.Merge(tbWBBST, false, MissingSchemaAction.Ignore);
                string title = ""; string room = "";
                foreach (DataRow row in dtOutput.Rows)
                {
                    title = "每日产量" + row["TIMERANGE"].ToString();
                    row["PCS"] = "1";
                    row["WBBSSTKLG"] = 0.001 * double.Parse(row["WBBSSTKLG"].ToString());
                    row["WAART"] = Helpers.Helper.GetGB2312Value(row["WAART"].ToString().Trim());
                    row["DCG"] = Helpers.Helper.GetGB2312Value(row["DCG"].ToString().Trim());
                    row["WABEZ"] = Helpers.Helper.GetGB2312Value(row["WABEZ"].ToString().Trim());
                    row["ABPARTEX"] = Helpers.Helper.GetGB2312Value(row["ABPARTEX"].ToString().Trim());
                    row["REMARK"] = Helpers.Helper.GetGB2312Value(row["REMARK"].ToString().Trim());
                    row["WBBSBRT"] = 0.01 * double.Parse(row["WBBSBRT"].ToString());
                    row["DCGQTY"] = 0.001 * double.Parse(row["DCGQTY"].ToString());
                    row["WBBHHK1"] = 0.001 * double.Parse(row["WBBHHK1"].ToString());
                    if (row["WBBREFSCHL"].ToString().Trim() == "1")
                    {
                        row["WBBREFSCHL"] = "甲班";
                    }
                    if (row["WBBREFSCHL"].ToString().Trim() == "2")
                    {
                        row["WBBREFSCHL"] = "乙班";
                    }
                    if (row["WBFMARKART"].ToString().Trim() == "1")
                    {
                        row["WBFMARKART"] = "甲班";
                    }
                    if (row["WBFMARKART"].ToString().Trim() == "2")
                    {
                        row["WBFMARKART"] = "乙班";
                    }
                    room = row["WBBWMLFDNR"].ToString().Substring(0, 1);
                    row["AMLB"] = room + "车间";
                    room = " ";
                }
                exAgent.DataTableToExcel(dtOutput, x + 1, 1);
                exAgent.SetCellValue(1, 1, 1);
                int count = dtOutput.Rows.Count;
                exAgent.BatchConvert2Number(x + 1, 7, count + x, 9);
                exAgent.BatchConvert2Number(x + 1, 11, count + x, 12);
                exAgent.SetCellValue(1, 2, title);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

    }
}
